package org.genntii.warehousesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.genntii.warehousesystem.domain.entity.Employee;

import java.time.LocalDate;

@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {

    @Select("select COUNT(*) from employee where username = #{username}")
    int usernameIsExist(@Param("username") String username);

    @Select("select password from employee where username = #{username};")
    String selectPassword(@Param("username") String username);

    @Select("select id from employee where username = #{username}")
    int selectIdByUsername(@Param("username") String username);

    @Update("update employee set name=#{name}," +
            "married=#{married}," +
            "education = #{education}," +
            "tel=#{tel}, " +
            "address = #{address}, " +
            "status=#{status} where id = #{id}")
    void employeeUpdate(@Param("name")String name,
                        @Param("married") Boolean married,
                        @Param("education")int education,
                        @Param("tel")String tel,
                        @Param("address")String address,
                        @Param("status") int status,
                        @Param("id")int id);

    @Update("update employee set termdate=#{date} where id = #{id}")
    void term(@Param("date")LocalDate date, @Param("id")int id);

}
